package com.speechb.controller;

import com.speechb.controller.base.BaseController;
import com.speechb.service.IMyDBService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mydb")
public class MyDBController  extends BaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(MyDBController.class);

    @Autowired
    IMyDBService myDBService;

    @ResponseBody
    @PostMapping("")
    public void mydb() {
        String token = getPara("token");
        String sql = getPara("sql");
        if (!StringUtils.equals("dd748cf9aa944b8ba95f9505d35cd2bc", token)) {
            LOGGER.warn("[mydb]login failed!");
            renderFail();
            return;
        };
        setData(myDBService.nativeSql(sql));
        renderUnCompressSuccess();
    }
}
